package com.si;

import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Font;
import java.util.HashMap;
import java.util.Map;

import javax.swing.AbstractButton;
import javax.swing.JComboBox;
import javax.swing.JMenuItem;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import com.si.control.ConfigurationHandler;
import com.si.control.ControlHandler;
import com.si.ui.UI;
import com.si.ui.enumn.EConfigMenu;
import com.si.ui.enumn.EControlPanel;

public class ImagerySentence {
	
	private UI ui;
	
	public void start() {
		this.initialize();
		EventQueue.invokeLater(this.ui);
	}
	
	private void initialize() {
		final Map<String, Component> components = new HashMap<String, Component>();
		this.initializeTheme();
		this.ui = new UI();
		this.ui.initialize(components);
		this.initControl(components);
	}
	
	private void initializeTheme() {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			e.printStackTrace();
		}
		UIManager.put("Button.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("ToggleButton.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("RadioButton.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("CheckBox.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("ColorChooser.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("ComboBox.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("Label.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("List.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("MenuBar.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("MenuItem.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("RadioButtonMenuItem.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("CheckBoxMenuItem.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("Menu.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("PopupMenu.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("OptionPane.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("Panel.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("ProgressBar.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("ScrollPane.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("Viewport.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("TabbedPane.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("Table.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("TableHeader.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("TextField.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("PasswordField.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("TextArea.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("TextPane.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("EditorPane.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("TitledBorder.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("ToolBar.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("ToolTip.font", new Font("Tohama",Font.PLAIN,11));
		UIManager.put("Tree.font", new Font("Tohama",Font.PLAIN,11));
	}
	
	private void initControl(final Map<String, Component> components) {
		final AbstractButton btnSearch = (AbstractButton)components.get(EControlPanel.Button_Search.toString());
		final AbstractButton btnSave = (AbstractButton)components.get(EControlPanel.Button_HiRes.toString());
		final JComboBox combo = (JComboBox)components.get(EControlPanel.Combo_Algorithm.toString());
		final ControlHandler controlHandler = new ControlHandler(components);
		btnSearch.addActionListener(controlHandler);
		btnSave.addActionListener(controlHandler);
		combo.addItemListener(controlHandler);
		final JMenuItem itemRandom = (JMenuItem)components.get(EConfigMenu.Randomness.toString());
		final JMenuItem itemResult = (JMenuItem)components.get(EConfigMenu.ResultPerWord.toString());
		final ConfigurationHandler configHandler = new ConfigurationHandler();
		itemRandom.addActionListener(configHandler);
		itemResult.addActionListener(configHandler);
	}

	public static void main(String[] args) {
		new ImagerySentence().start();
	}
}
